<template>
  <Layout style="height: 100%" class="main">
    <Header>
      <div class="logo-v3">
        <img :src="logoTime" @click="clickMenuList()" class="logo-image-div"/>
        <img :src="logoImg" class="logo-image-div1"/>
          <div class="user-div">
            <Dropdown :transfer="true" @on-click="clickDropMenu">
              <Row>
                <Col span="20">
                  <Row>
                    <div class="name-div">
                      <a href="javascript:void(0)" @click="handleOpen">
                        {{personData.name}}
                        <Icon type="ios-arrow-down"></Icon>
                      </a>
                    </div>
                  </Row>
                  <Row>
                    <div class="commit-div commit-title">
                            [{{personData.company_name}}]
                    </div>
                  </Row>
                </Col>
                <Col span="3" offset="1">
                  <Avatar style="background-color: #DB4B00">{{ personData.name }}</Avatar>
                </Col>
              </Row>
              <DropdownMenu slot="list">
                <div class="top-div">
                  <div class="index-title3">{{personData.name}}</div>
                  <div class="index-title4">[{{personData.company_name}}]</div>
                  <div class="level-div index-title5">{{grade_level}}</div>
                </div>
                <div v-for="(item, index) in menuItemList" v-bind:key="index">
                  <DropdownItem :name="item.path">
                    <Row class="drop-item-div1">
                      <Col span="3">
                        <img :src="item.url" />
                      </Col>
                      <Col span="16">
                        <div class="index-title3" style="float:left;">{{item.label}}</div>
                      </Col>
                    </Row>
                  </DropdownItem>
                </div>
                <div style="float:left;margin-bottom: 5px;margin-top:15px;">
                  <div class="back-div index-title2" @click="backTo('new-register-display')">返回主页</div>
                  <img :src="tcdlImg" @click="logout()" style="width: 104px;height: 30px;float:left;cursor: pointer;" />
                </div>
              </DropdownMenu>
            </Dropdown>
          </div>
      </div>
    </Header>
    <Modal
      v-model="CommunityModal"
      title="完善社区基本信息"
      @on-ok="saveCommunityModal">
      <Form :model="communityDetail" :label-width="120">
        <FormItem label="社区简介">
          <Input v-model="communityDetail.detail" placeholder="请输入名称"></Input>
        </FormItem>
        <FormItem label="社区面积">
          <Input v-model="communityDetail.area" placeholder="请输入名称"></Input>
        </FormItem>
        <FormItem>
          <Upload multiple action="http://120.27.63.37:38081/api/ac/file/fileCommonService/upLoadFiles" :before-upload="beforeUpload">
            <img v-if="communityDetail.imgShow || communityDetail.label_img" :src="communityDetail.label_img" style="width: 50px;height: 50px;margin-bottom: 20px"/>
            <Button icon="ios-cloud-upload-outline" style="margin-bottom: 20px">上传社区图片</Button>
          </Upload>
        </FormItem>
      </Form>
    </Modal>
    <Modal v-model="modalDevice1" title="下载中心" width="700"
               style="position:relative;">
          <div style="line-height:25px">
            <div style="font-size: 14px;color: #2E2D3C;font-weight: bold;margin-bottom: 20px">设备驱动下载</div>
            <div >捷宇高拍仪
            </div>
            <div>良田高拍仪
              <a style="margin-right: 50px;margin-left: 50px" href="https://pan.baidu.com/s/1Sp7a4Mw3BU-4stZM-zRJOA" target="_blank">https://pan.baidu.com/s/1Sp7a4Mw3BU-4stZM-zRJOA</a>
              <span>提取码：qfsi</span></div>
            <div>紫图高拍仪
              <a style="margin-right: 35px;margin-left: 50px" href="https://pan.baidu.com/s/1CM7b4_EiRI33HkuByBjuCw" target="_blank">https://pan.baidu.com/s/1CM7b4_EiRI33HkuByBjuCw</a>
              <span>提取码：6hso</span></div>
            <div>德意拍高拍仪
              <a style="margin-right: 60px;margin-left: 40px" href="https://pan.baidu.com/s/1RMOLv2xXtwqh8pCFfFSrtA" target="_blank">https://pan.baidu.com/s/1RMOLv2xXtwqh8pCFfFSrtA</a>
              <span>提取码：8mzs</span>
            </div>
            <div>维山高拍仪
              <a style="margin-right: 60px;margin-left: 40px" href="https://pan.baidu.com/s/1ee3QkVNVP4xJskVsOgnvFA" target="_blank">https://pan.baidu.com/s/1ee3QkVNVP4xJskVsOgnvFA</a>
              <span>提取码：saw4</span>
            </div>
            <div>点易拍高拍仪</div>
          </div>
          <Divider/>
          <div style="line-height:25px">
            <div style="font-size: 14px;color: #2E2D3C;font-weight: bold;margin-bottom: 20px">培训视频下载</div>
            <div>视频
              <a style="margin-right: 50px;margin-left: 90px" href="https://pan.baidu.com/s/1vSMpSicWSTuLqVa5i2173g" target="_blank">https://pan.baidu.com/s/1vSMpSicWSTuLqVa5i2173g</a>
              <span>提取码：lj2w</span>
            </div>
          </div>
        </Modal>
        <Modal v-model="modalDevice" title="选择该社区使用的设备" width="500" cancel-text="关闭"
               @on-ok="saveDevice()" @on-cancel="modalDevice = false" ok-text="确定"
               style="position:relative;">
          <div style="display: table-caption; line-height:25px">
            <RadioGroup v-model="highMeter1">
              <Radio label="JieYuDevice">
                <span>捷宇高拍仪</span>
              </Radio>
              <Radio label="LiangTianDevice">
                <span>良田高拍仪</span>
              </Radio>
              <Radio label="ZiTuDevice">
                <span>紫图高拍仪</span>
              </Radio>
              <Radio label="DeYiPaiDevice">
                <span>德意拍高拍仪</span>
              </Radio>
              <Radio label="WeiShanDevice">
                <span>维山高拍仪</span>
              </Radio>
              <Radio label="DianYiPaiDevice">
                <span>点易拍高拍仪</span>
              </Radio>
            </RadioGroup>
          </div>
        </Modal>
        <Modal v-model="modalDevice2" width="900"
               style="position:relative;">
          <div style="padding:50px" v-html="modalDevice2html">
          </div>
          <Divider/>
        </Modal>
        <Modal v-model="display_model1_obj1.modal1" width="900" :mask-closable="false">
          <div style="padding:50px" v-html="display_model1_obj1.html">
          </div>
          <div slot="footer">
            <Button type="primary" :disabled="!disabledCodeBtn" @click="savelogea">{{time}}确认</Button>
          </div>
        </Modal>
        <Modal v-model="modalQr" title="二维码" width="500" cancel-text="关闭"
               @on-ok="modalQr = false" @on-cancel="modalQr = false" ok-text="确定"
               style="position:relative;">
          <div id="qrcode" ref="qrcode" style="margin-left: 18%"></div>
          <div style="text-align: center;margin-top: 10px;font-size: 1rem;">扫描二维码绑定用户信息</div>
        </Modal>
    <img id="box" :src="imgUrl" @click="checkMenu()" :class="{'btn1': isCollapsed, 'btn2': !isCollapsed}"/>
    <Layout class="new-menu">
      <Sider class="sider-menu-div" hide-trigger collapsible :collapsed-width="0" :style="{background: '#fafafa', width: '240px'}" style="height: 100%; overflow-y: scroll" v-model="isCollapsed" @on-collapse="aaa">
            <Menu theme="light" width="auto" :class="menuitemClasses" @on-select="clickMenu">
              <div v-for="(item, index) in minZhengMenus1" v-bind:key="index">
                <Submenu :name="item.name || ''" v-show="item.list && item.list.length >= 1">
                  <template slot="title">
                      <Icon :type="item.icon"></Icon>
                      {{item.name}}
                  </template>
                  <div v-for="(item1, index1) in item.list" v-bind:key="index1">
                    <MenuItem :name="item1.path || ''">
                      <Icon :type="item1.icon"></Icon>
                      <span>{{item1.name}}</span>
                    </MenuItem>
                  </div>
                </Submenu>
                <MenuItem :name="item.path" v-if="!item.list" :key="item.type_id" v-show="!item.hidden"
                          :class="item.audit_state_yingshang == '1' ? 'mz-gray' : ''">
                    <Icon :type="item.icon" :key="item.type_id"/>
                    {{item.name}}
                </MenuItem>
              </div>
            </Menu>
      </Sider>
      <Modal v-model="display_model1_obj.modal1" :title="display_model1_obj.text" width="900">
        <div id="printMe">
          <Form label-position="right" :label-width="100">
            <Row>
              <Col span="24" class="ivu-form-item-content" style="text-align: center">
                <embed width="800" v-show="display_model1_obj.modal1" height="600"
                       :src="display_model1_obj.filepath"></embed>
              </Col>
            </Row>
          </Form>
        </div>
        <div slot="footer">
          <Button type="error" size="large" @click="display_model1_obj.modal1=false">关闭</Button>
        </div>
      </Modal>
      <Modal v-model="passwordInfo.show" title="修改密码" width="600" :closable="false" :mask-closable="false">
        <Form label-position="left" :label-width="100" ref="passwordInfo" :model="passwordInfo"
              :rules="ruleInline">
          <FormItem prop="oldpassword" label="旧密码：" class="set-password-input">
            <Input type="password" v-model="passwordInfo.oldpassword"></Input>
          </FormItem>
          <FormItem prop="newpassword" label="新密码：" class="set-password-input">
            <Input type="password" v-model="passwordInfo.newpassword"></Input>
          </FormItem>
          <FormItem prop="repassword" label="确认密码：" class="set-password-input">
            <Input type="password" v-model="passwordInfo.repassword"></Input>
          </FormItem>
        </Form>
        <div slot="footer">
          <div class="left-con" style="margin-top: 56px;height:32px;">
            <div class="search-btn" @click="setPassWord('passwordInfo')">确  认</div>
            <div class="remove-btn" @click="closePassWord('passwordInfo')">取  消</div>
          </div>
        </div>
      </Modal>
      <Layout class="content-layout-v3" :style="{overflow: 'hidden',maxHeight: maxH+'px',overflowY:'scroll'}">
        <Content :style="{paddingLeft: '25px', paddingTop: '40px', paddingRight: '40px', paddingBottom: '47px', background: '#f2f2f2'}">
          <keep-alive :include="cacheList">
            <router-view/>
          </keep-alive>
        </Content>
      </Layout>
      <menu-list :menu-list="minZhengMenus" :menu-list1="minZhengMenus1" :menu-list2="minZhengMenus2" :menu-list3="minZhengMenus3" :menu_flag="menu_flag" :menu_flag1="menu_flag1" :menu_flag2="menu_flag2" :menu_flag3="menu_flag3" @getSearchMenu="getSearchMenu" ref="menu"></menu-list>
    </Layout>
  </Layout>
</template>

<script>
import './index-copy.less'
import logoTime from '@/assets/images/new-register/index-menu.png'
import logoImg from '@/assets/images/new-register/logo.png'
import rightImg from '@/assets/images/new-register/right.png'
import leftImg from '@/assets/images/new-register/left.png'
import logoutImg from '@/assets/images/new-register/logout.png'
import passwordImg from '@/assets/images/new-register/password.png'
import cjwtImg from '@/assets/images/new-register/常见问题图标.png'
import kfImg from '@/assets/images/new-register/客服图标.png'
import mmImg from '@/assets/images/new-register/密码图标.png'
import sbbdImg from '@/assets/images/new-register/设备绑定图标.png'
import sppxImg from '@/assets/images/new-register/视频培训图标.png'
import tcdlImg from '@/assets/images/new-register/退出登录.png'
import xzImg from '@/assets/images/new-register/下载图标.png'
import { mapMutations, mapActions, mapGetters } from 'vuex'
import { updatePwd } from '@/api/user'
import { mzMenulist } from '@/api/eventlist' // findHtmlList, getHtml1, savelog
import ThreeMenu from './three-menu'
import device from '@/view/demo/device'
import { clearInterval } from 'timers'
import QRCode from 'qrcodejs2'
import { updateUserGPY } from '@/api/common'
import YiqingMenu from '@/view/xian-page/indexv3/yiqing-menu/yiqing-menu'
import TagsNav from '@/components/main/components/tags-nav'
import { getNewTagList, routeEqual, getMenuByRouter, localSave, localClear } from '@/libs/util'
import { getRouterReq } from '@/api/routers'
import routers from '@/router/routers'
import { createUpLoadFiles, getSign } from '../../../api/common'
// import { getCompanyDetailByCode, saveCompanyDetail } from '../../../api/eventlist'
import MenuList from '@/components/menu-list'
export default {
  name: 'indexv3',
  components: {
    MenuList,
    YiqingMenu,
    ThreeMenu,
    device,
    TagsNav
    // TransitionNotice
    // scrollAd
  },
  data () {
    const validatePassCheck = (rule, value, callback) => {
      if (value !== this.passwordInfo.newpassword) {
        callback(new Error('确认密码与新密码不相同'))
      } else {
        callback()
      }
    }
    return {
      menuItemList: [
        // {
        //   url: kfImg,
        //   label: '客服',
        //   path: ''
        // },
        // {
        //   url: xzImg,
        //   label: '云下载',
        //   path: ''
        // },
        // {
        //   url: cjwtImg,
        //   label: '常见问题',
        //   path: ''
        // },
        // {
        //   url: sppxImg,
        //   label: '视频培训',
        //   path: ''
        // },
        // {
        //   url: sbbdImg,
        //   label: '设备绑定',
        //   path: ''
        // },
        {
          url: mmImg,
          label: '修改密码',
          path: 'setPasword'
        }
      ],
      cjwtImg,
      kfImg,
      mmImg,
      sbbdImg,
      sppxImg,
      tcdlImg,
      xzImg,
      visible: false,
      minZhengMenus: [],
      minZhengMenus1: [],
      minZhengMenus2: [],
      minZhengMenus3: [],
      isCollapsed: true,
      isCollapse: true,
      communityDetail: {
        imgShow: false
      },
      CommunityModal: false,
      upPicData: {
        fileName: 'label',
        filePath: 'grid/label'
      },
      company_grade: '',
      menuName: '',
      device_code: '', // 高拍仪参数
      highMeter1: '', // 高拍仪
      highMeter2: '', // 高拍仪
      highMeter3: '', // 高拍仪
      type: '',
      shuju: [],
      codeUrl: '',
      company_codes: '',
      loginCompanyType: '1', // 登录账号类型 1城市 2农村
      loginNames: '',
      modalDevice: false,
      modalDevice1: false,
      modalDevice2: false,
      modalDevice3: true,
      disabledCodeBtn: false,
      htmllist: [],
      time: '',
      display_model1_obj1: { modal1: false, filepath: '', html: '' },
      modalDevice2html: '',
      modalQr: false,
      timerInterval: null,
      collapsed: false,
      reloadItem: false,
      logoTime,
      logoImg,
      rightImg,
      leftImg,
      logoutImg,
      passwordImg,
      totalItemNum: 0,
      totalBMNum: 0,
      treeDataList: [],
      searchName: '',
      personData: {},
      routeList: [],
      passwordInfo: { show: false },
      display_model1_obj: { modal1: false, filepath: '' },
      maxH: `${document.documentElement.clientHeight}` - 50,
      btnH: `${document.documentElement.clientHeight}` / 2,
      ruleInline: {
        oldpassword: [
          { required: true, message: '请填写旧密码', trigger: 'blur' }
        ],
        newpassword: [
          { required: true, message: '新密码不能为空', trigger: 'blur' },
          { type: 'string', min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
        ],
        repassword: [
          { required: true, message: '请填写确认密码', trigger: 'blur' },
          { type: 'string', min: 6, message: '密码长度不能少于6位', trigger: 'blur' },
          { validator: validatePassCheck, trigger: 'blur' }
        ]
      },
      yiQingMenus: [],
      adList: [
        // { content: '全科社工们，系统喊你快来试用', ink: 'xx.com' }
      ],
      location_url: '',
      textArr: [],
      number: 0,
      tempTagNavList: [],
      imgUrl: rightImg,
      dataList: [],
      dataList1: [],
      dataList2: [],
      dataList3: [],
      menu_flag: false,
      menu_flag1: false,
      menu_flag2: false,
      menu_flag3: false
    }
  },
  computed: {
    menuitemClasses: function () {
      return [
        'menu-item',
        this.isCollapsed ? 'collapsed-menu' : ''
      ]
    },
    text () {
      return {
        id: this.number,
        val: this.textArr[this.number]
      }
    },
    ...mapGetters([
      'errorCount'
    ]),
    tagNavList () {
      return this.$store.state.app.tagNavList
    },
    tagRouter () {
      return this.$store.state.app.tagRouter
    },
    userAvator () {
      return this.$store.state.user.avatorImgPath
    },
    cacheList () {
      const list = ['ParentView', ...this.tagNavList.length ? this.tagNavList.filter(item => !(item.meta && item.meta.notCache)).map(item => item.name) : []]
      return list
    },
    local () {
      return this.$store.state.app.local
    },
    hasReadErrorPage () {
      return this.$store.state.app.hasReadErrorPage
    },
    unreadCount () {
      return this.$store.state.user.unreadCount
    },
    grade_level () {
      let company_grade = this.$store.state.user.severUserInfo.company_grade
      let grade_level = ''
      switch (company_grade) {
        case '2':
          grade_level = '市级账号'
          break
        case '3':
          grade_level = '区级账号'
          break
        case '4':
          grade_level = '街道账号'
          break
        case '5':
          grade_level = '社区账号'
          break
        default:
      }
      return grade_level
    }
  },
  methods: {
    backTo (name) {
      console.log(window.location.href, '####')
      if (window.location.href.indexOf('iviewys') !== -1) { // 临时搭的测试环境访问生产环境数据
        window.location = 'http://iviewys.tripln.top/#/management_platform'
      } else if (window.location.href.indexOf('qstb') !== -1) {
        window.location = 'http://qstb.mzj.shenyang.gov.cn/#/management_platform'
      } else if (window.location.href.indexOf('iview') !== -1) {
        window.location = 'http://iview.tripln.top/#/management_platform'
      } else {
        this.$router.push({
          path: name
        })
      }
    }, // 返回首页
    handleOpen () {
      this.visible = true
    },
    getSearchMenu (text) {
      this.getSearchList(text)
    },
    getSearchList (text) {
      let array = JSON.parse(JSON.stringify(this.dataList))
      let array1 = JSON.parse(JSON.stringify(this.dataList1))
      let array2 = JSON.parse(JSON.stringify(this.dataList2))
      let array3 = JSON.parse(JSON.stringify(this.dataList3))
      this.minZhengMenus = []
      this.minZhengMenus1 = []
      this.minZhengMenus2 = []
      this.minZhengMenus3 = []
      array.forEach(item => { // 网格
        if (item.name.indexOf(text) !== -1) {
          this.minZhengMenus.push(item)
        }
      })
      if (this.minZhengMenus.length === 0) {
        this.menu_flag = false
      }
      array1.forEach(item => { // 实名制
        if (text) {
          if (item.list) {
            item.list.forEach(element => {
              if (text) {
                if (element.name.indexOf(text) !== -1) {
                  this.minZhengMenus1.push(item)
                }
              } else {
                this.minZhengMenus1.push(item)
              }
            })
          } else {
            if (item.name.indexOf(text) !== -1) {
              this.minZhengMenus1.push(item)
            }
          }
        } else {
          this.minZhengMenus1.push(item)
        }
      })
      if (this.minZhengMenus1.length === 0) {
        this.menu_flag1 = false
      }
      array2.forEach(item => { //  全市通办
        if (text) {
          if (item.list) {
            item.list.forEach(element => {
              if (text) {
                if (element.name.indexOf(text) !== -1) {
                  console.log(element.name, '相等')
                  this.minZhengMenus2.push(item)
                }
              } else {
                this.minZhengMenus2.push(item)
              }
            })
          } else {
            if (item.name.indexOf(text) !== -1) {
              this.minZhengMenus2.push(item)
            }
          }
        } else {
          this.minZhengMenus2.push(item)
        }
      })
      if (this.minZhengMenus2.length === 0) {
        this.menu_flag2 = false
      }
      array3.forEach(item => { // 疫情
        if (text) {
          if (item.list) {
            item.list.forEach(element => {
              if (text) {
                if (element.name.indexOf(text) !== -1) {
                  console.log(element.name, '相等')
                  this.minZhengMenus3.push(item)
                }
              } else {
                this.minZhengMenus3.push(item)
              }
            })
          } else {
            if (item.name.indexOf(text) !== -1) {
              this.minZhengMenus3.push(item)
            }
          }
        } else {
          this.minZhengMenus3.push(item)
        }
      })
      if (this.minZhengMenus3.length === 0) {
        this.menu_flag3 = false
      }
      this.$refs.menu.getSearchFlag(this.menu_flag, this.menu_flag1, this.menu_flag2, this.menu_flag3)
    }, // 搜索菜单
    mzMenulist (text) {
      // let menu_id = '3c649d25-f33c-11ea-88c8-0242ac11000f'
      let menu_id = ''
      if (window.location.href.indexOf('iviewys') !== -1) {
        menu_id = 'f782240b-c3ee-11ed-a868-0242c0a81f02'
      } else {
        menu_id = '3c649d25-f33c-11ea-88c8-0242ac11000f'
      }
      mzMenulist(menu_id).then(ret => {
        if (ret.data.errcode === 0) {
          this.minZhengMenus = ret.data.data.list[0].list
          this.dataList = JSON.parse(JSON.stringify(this.minZhengMenus))
          this.minZhengMenus.forEach(item => {
            if (item.path === this.$route.path) {
              this.menuName = item.name
            }
          })
          if (this.minZhengMenus.length === 0) { // 查不到数据说明没有权限，则显示暂无权限
            this.flag = true
          }
        }
      })
    },
    qstbMenulist (text) { // 全市通办
      // let menu_id = 'ad0e1852-a088-11ea-9adb-0242ac110002,12aadfd4-41ea-11e7-b04c-ecf4bbcc9540'
      let menu_id = ''
      if (window.location.href.indexOf('iviewys') !== -1) {
        menu_id = 'ff79cddd-c3ee-11ed-a868-0242c0a81f02,12aadfd4-41ea-11e7-b04c-ecf4bbcc9540'
      } else {
        menu_id = 'ad0e1852-a088-11ea-9adb-0242ac110002,12aadfd4-41ea-11e7-b04c-ecf4bbcc9540'
      }
      mzMenulist(menu_id).then(ret => {
        if (ret.data.errcode === 0) {
          this.minZhengMenus2 = ret.data.data.list
          this.dataList2 = JSON.parse(JSON.stringify(this.minZhengMenus2))
          this.minZhengMenus2.forEach(item => {
            if (item.path === this.$route.path) {
              this.menuName = item.name
            }
          })
        }
      })
    },
    smzMenulist (text) { // 实名制
      // let menu_id = 'abf84050-12ca-11eb-b210-0242ac11000f'
      let menu_id = ''
      if (window.location.href.indexOf('iviewys') !== -1) {
        menu_id = '02eabddb-c3ef-11ed-a868-0242c0a81f02'
      } else {
        menu_id = 'abf84050-12ca-11eb-b210-0242ac11000f'
      }
      mzMenulist(menu_id).then(ret => {
        if (ret.data.errcode === 0) {
          this.minZhengMenus1 = ret.data.data.list
          this.dataList1 = JSON.parse(JSON.stringify(this.minZhengMenus1))
          this.minZhengMenus1.forEach(item => {
            if (item.path === this.$route.path) {
              this.menuName = item.name
            }
          })
        }
      })
    },
    yqfkMenulist (text) { // 疫情防控
      let menu_id = 'c4b9a902-a088-11ea-9adb-0242ac110002'
      mzMenulist(menu_id).then(ret => {
        if (ret.data.errcode === 0) {
          this.minZhengMenus3 = ret.data.data.list[0].list
          this.dataList3 = JSON.parse(JSON.stringify(this.minZhengMenus3))
          this.minZhengMenus3.forEach(item => {
            if (item.path === this.$route.path) {
              this.menuName = item.name
            }
          })
        }
      })
    },
    clickMenuList () {
      console.log('$$$$$')
      this.$refs.menu.open()
    },
    clickDropMenu (name) {
      if (name === 'logout') {
        this.logout()
      }
      if (name === 'setPasword') {
        this.passwordInfo.show = true
      }
    },
    aaa (name) {
      console.log(name, '回调')
      if (name === true) {
        setTimeout(() => {
          this.imgUrl = this.rightImg
        }, 200)
      } else if (name === false) {
        setTimeout(() => {
          this.imgUrl = this.leftImg
        }, 200)
      }
    },
    clickMenu (item) {
      console.log(item, '%%%%%%')
      this.$router.push({
        path: item
      })
    },
    // 点击按钮，切换菜单的折叠与展开
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    },
    checkMenu (flag) {
      this.isCollapsed = !this.isCollapsed
      var box = document.getElementById('box')
      box.hidden = true
      setTimeout(() => {
        box.hidden = false
      }, 200)
      // box.offsetLeft = 180
      // box.remove()
    },
    clickMenu1 (flag) {
      this.isCollapse = true
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    },
    beforeUpload (file) {
      this.upPicData.fileName = 'label'
      this.upPicData.filePath = 'grid/label'
      var time = new Date().getTime()
      let timeStep = time.toString()
      let that = this
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        that.upPicData.fileName = that.upPicData.fileName + timeStep + '.' + file.type.substring(6)
        that.upPicData.file = reader.result.substring(index)
        that.upPic(that.upPicData)
      }
      return false
    },
    upPic (obj) {
      var time = new Date().getTime()
      let timeStep = time.toString()
      let param = {
        filePath: obj.filePath,
        fileName: obj.fileName,
        timestamp: timeStep
      }
      getSign(param).then(res => {
        if (res.data.errcode === 0) {
          let url = res.data.data.docking_url
          let params = {
            sign: res.data.data.sign,
            timestamp: timeStep,
            filePath: obj.filePath,
            fileName: obj.fileName,
            file: obj.file
          }
          createUpLoadFiles(url, params).then(res => {
            if (res.data.errcode === 0) {
              this.communityDetail.label_img = res.data.data
              this.communityDetail.imgShow = true
            } else {
              this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
            }
          })
        } else {
          this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
        }
      })
    },
    // clickCommunityModal () {
    //   getCompanyDetailByCode().then(ret => {
    //     if (ret.data.errcode === 0 || ret.data.errcode === 10003) {
    //       if (ret.data.errcode === 0) {
    //         this.communityDetail = ret.data.data
    //       }
    //       this.CommunityModal = true
    //     } else {
    //       this.$Notice.error({ title: '查询失败！', desc: ret.data.msg })
    //     }
    //   })
    // },
    saveCommunityModal () {
      // saveCompanyDetail(this.communityDetail).then(ret => {
      //   if (ret.data.errcode === 0) {
      //     this.$Notice.success({ title: '保存成功！', desc: ret.data.msg })
      //   } else {
      //     this.$Notice.error({ title: '查询失败！', desc: ret.data.msg })
      //   }
      // })
    },
    hreftwo () {
      this.$router.push({ path: '/message' })
    },
    startMove () {
      // eslint-disable-next-line
        let timer = setTimeout(() => {
        if (this.number === this.textArr.length) {
          this.number = 0
        } else {
          this.number += 1
        }
        this.startMove()
      }, 2500) // 滚动不需要停顿则将2000改成动画持续时间
    },
    ...mapActions([
      'handleLogOut'
    ]),
    getNetworkIp () {
      let needHost = '' // 打开的host
      try {
        // 获得网络接口列表
        let network = os.networkInterfaces()
        for (let dev in network) {
          let iface = network[dev]
          for (let i = 0; i < iface.length; i++) {
            let alias = iface[i]
            if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
              needHost = alias.address
            }
          }
        }
      } catch (e) {
        needHost = 'localhost'
      }
      return needHost
    },
    logout () {
      this.handleLogOut().then(() => {
        clearInterval(this.timerInterval)
        localClear()
        if (location.href.indexOf('qstb.mzj.shenyang.gov.cn') !== -1) { // 生产环境
          window.open('http://qstb.mzj.shenyang.gov.cn/#/login')
        } else if (location.href.indexOf('http://iviewys.tripln.top') !== -1) { // 演示环境
          window.open('http://iviewys.tripln.top/#/login')
        } else if (location.href.indexOf('http://iview.tripln.top') !== -1) { // 演示环境
          window.open('http://iview.tripln.top/#/login')
        } else { // 本地环境
          this.$router.push({ name: 'login' })
          // window.open('http://iviewys.tripln.top')
        }
      })
    },
    closePassWord (name) {
      this.passwordInfo.show = false
      this.$refs[name].resetFields()
    },
    setPassWord (name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          updatePwd(this.passwordInfo).then(res => {
            if (res.data.data) {
              this.$Notice.success({ title: '修改成功', desc: '修改密码后需要重新登录' })
              this.passwordInfo.show = false
              this.logout()
            } else {
              this.$Notice.error({ title: '修改失败', desc: res.data.errmsg })
            }
          })
        } else {
          this.$Notice.error({ title: '信息错误', desc: '密码修改信息错误，请重新填写' })
        }
      })
    },
    viewProcess (item) {
      if (item.file_url) {
        this.display_model1_obj.text = item.type_name
        this.display_model1_obj.modal1 = true
        this.display_model1_obj.filepath = item.file_url
      } else {
        this.$Notice.error({ title: '无文件', desc: '当前事项无PDF说明文档' })
      }
    },
    openPage (e) {
      console.log('!!!', e)
      // console.log('!!!!!', e)
      if (e) {
        let a = e.split('=')
        this.menuName = a[0]
        this.$router.push({ path: a[1] })
      } else {
        this.$Notice.error({ title: '无文件', desc: '等待添加路径' })
      }
    },
    searchList1 () {
      if (!this.searchName) {
        this.searchList()
      }
    },
    searchList () {
      this.reloadItem = true
      this.treeDataList.forEach(e1 => {
        e1.hidden = true
        if (e1.children) {
          let curNum1 = 0
          e1.children.forEach(e2 => {
            if (e2.children) {
              let curNum2 = 0
              e2.children.forEach(e3 => {
                e3.hidden = true
                if (e3.type_name.indexOf(this.searchName) >= 0) {
                  e3.hidden = false
                  curNum2++
                  curNum1++
                }
              })
              e2.hidden = true
              if (curNum2 > 0) {
                e2.count = curNum2
                e2.hidden = false
              }
            } else {
              e2.hidden = true
              if (e2.type_name.indexOf(this.searchName) >= 0) {
                e2.hidden = false
                curNum1++
              }
            }
          })
          if (curNum1 > 0) {
            e1.count = curNum1
            e1.hidden = false
          }
        } else {
          if (!this.searchName) {
            e1.hidden = false
          }
        }
      })
      this.$nextTick(() => {
        this.reloadItem = false
      })
    },
    getCode (codeUrl) {
      var qrcode = new QRCode(document.getElementById('qrcode'), {
        text: codeUrl,
        top: 200,
        width: 300,
        height: 300,
        colorDark: '#000000',
        colorLight: '#ffffff',
        correctLevel: QRCode.CorrectLevel.H
      })
      return qrcode
    },
    // 驱动下载
    deviceBinding1 () {
      console.log('设备绑定')
      this.modalDevice1 = true
    },
    // 设备绑定
    deviceBinding () {
      console.log('设备绑定')
      this.modalDevice = true
    },
    // 客服电话
    deviceBinding2 () {
      console.log('客服电话')
      this.modalDevice2 = true
    },
    saveDevice () {
      updateUserGPY({ device_code: this.highMeter1 }).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '设备绑定成功', desc: '设备绑定成功，请注销重新登录' })
        } else {
          this.$Notice.error({ title: '绑定失败', desc: res.data.errmsg })
        }
      })
      this.$store.state.user.highMeter = this.highMeter1
    },
    ...mapMutations([
      'setBreadCrumb',
      'setTagNavList',
      'addTag',
      'setLocal',
      'setFirstMenuId',
      'setHomeRoute',
      'closeTag'
    ]),
    ...mapActions([
      'handleLogin',
      'getUnreadMessageCount',
      'getAjaxRouterData'
    ]),
    turnToPage (route) {
      // console.log(route, 'main/turnToPage')
      let { name, params, query } = {}
      if (typeof route === 'string') name = route
      else {
        name = route.name
        params = route.params
        query = route.query
      }
      if (name.indexOf('isTurnByHref_') > -1) {
        window.open(name.split('_')[1])
        return
      }
      this.$router.push({
        name,
        params,
        query
      })
    },
    handleCollapsedChange (state) {
      this.collapsed = state
    },
    handleCloseTag (res, type, route) {
      if (type !== 'others') {
        if (type === 'all') {
          this.turnToPage(this.$config.homeName)
        } else {
          if (routeEqual(this.$route, route)) {
            this.closeTag(route)
          }
        }
      }
      this.setTagNavList(res)
    },
    handleClick (item) {
      // console.log(item, '执行main/handleClick')
      this.turnToPage(item)
    },
    getRouterListData () {
      getRouterReq('222').then(res => {
        let listData = getMenuByRouter(res.data, 'admin')
        this.menuList001 = listData
      })
    },
    groupMenuSelect (id, menusData) {
      // this.setFirstMenuId(id)
      localSave('first-menus-data', JSON.stringify(menusData))
      this.$store.dispatch('getAjaxRouterData', id)
    },
    // findHtmlList () {
    //   findHtmlList({}).then(res => {
    //     if (res.data.errcode === 0) {
    //       if (res.data.data) {
    //         this.htmllist = res.data.data
    //         this.opennoticeDocument()
    //       }
    //     }
    //   })
    // },
    opennoticeDocument () {
      for (var i in this.htmllist) {
        let item = this.htmllist[i]
        if (item.isshow === '1') {
          this.display_model1_obj1.html = item.html
          this.display_model1_obj1.index_id = item.id
          this.display_model1_obj1.modal1 = true
          item.isshow = '0'
          this.countDown(item.showtime)
          return
        }
      }
    },
    showkefu () {
      getHtml1({}).then(res => {
        if (res.data.errcode === 0) {
          this.modalDevice2html = res.data.data.html
        }
      })
    },
    countDown (time) {
      this.time = time + 's'
      if (time === 0) {
        this.disabledCodeBtn = true
        this.time = ''
        return
      } else {
        this.disabledCodeBtn = false
        time--
      }
      setTimeout(() => {
        this.countDown(time)
      }, 1000)
    },
    savelogea () {
      let params = {
        index_id: this.display_model1_obj1.index_id
      }
      savelog(params).then(res => {})
      this.display_model1_obj1.modal1 = false
      setTimeout(() => {
        this.opennoticeDocument()
      }, 500)
    }
  },
  watch: {
    '$route' (newRoute) {
      console.log(newRoute, 'watch新的路由变化')
      // console.log(this.menuList, '获取当菜单数据')
      let tempMenuList = this.menuList
      for (let key in tempMenuList) {
        let childData = tempMenuList[key].children
        if (tempMenuList[key].name && tempMenuList[key].name === newRoute.name) {
          console.log('ok11')
          newRoute.meta.title = tempMenuList[key].meta.title // 为了不在路由里面取名字写的循环
        } else {
          if (tempMenuList[key].children && tempMenuList[key].children.length > 0) {
            for (let k2 in childData) {
              let chid = childData[k2]
              if (chid.name === newRoute.name) {
                console.log('ok')
                newRoute.meta.title = chid.meta.title // 为了不在路由里面取名字写的循环
              }
            }
          }
        }
      }
      const { name, query, params, meta } = newRoute
      if (newRoute.meta.hide === true) {
        this.addTag({
          route: { name, query, params, meta },
          type: 'push'
        })
        this.setBreadCrumb(newRoute)
        this.tempTagNavList = []
        for (var i = 0; i < this.tagNavList.length; i++) {
          if (this.tagNavList[i].meta.hide === true) {
            this.tempTagNavList.push(this.tagNavList[i])
          }
        }
        this.setTagNavList(getNewTagList(this.tempTagNavList, newRoute))
      }
    }
  },
  mounted () {
    console.log(this.grade_level, '登记')
    this.startMove()
    this.location_url = window.location.href
    this.mzMenulist()
    this.qstbMenulist()
    this.smzMenulist()
    this.yqfkMenulist()
    this.setTagNavList()
    this.setHomeRoute(routers)
    const { name, params, query, meta } = this.$route
    this.addTag({
      route: { name, params, query, meta }
    })
    let severUserInfo = this.$store.state.user.severUserInfo
    this.company_grade = severUserInfo.company_grade
    this.loginCompanyType = severUserInfo.company_type
    this.device_code = severUserInfo.email
    this.company_codes = severUserInfo.company_code
    this.loginNames = severUserInfo.loginName
    this.personData.name = severUserInfo.name
    this.personData.company_name = severUserInfo.company_name
    this.highMeter1 = severUserInfo.email
    this.routeList = this.$store.state.app.mainv3Nav
    // this.showkefu()
  }
}
</script>
<style lang="less" scoped>
  .new-menu .ivu-menu-light.ivu-menu-vertical .ivu-menu-item-active:not(.ivu-menu-submenu) {
    color: #B40001;
    background: white;
    z-index: 2;
    height: 45px;
    border-radius: 5px;
    background: #efefef;
    margin-left: 10px;
    margin-right: 10px;
    padding-left: 10px;
    padding-right: 0px;
  }
  .new-menu .ivu-menu-item:hover {
      color: #B40001;
      font-weight: bold;
  }
  .new-menu /deep/ .ivu-menu-vertical .ivu-menu-submenu-title:hover {
    color: #B40001;
  }
  .ivu-select-dropdown {
    padding: 5px 0 10px 0;
  }
  .ivu-dropdown-menu {
    min-width: 100px;
    width: 238px;
    padding: 5px 10px;
  }
  .ivu-dropdown-item {
    padding: 5px 0px;
  }
  .ivu-dropdown-item:hover {
    padding: 5px 0px;
    background: #FFFAE8;
  }
  /deep/ .ivu-modal-header {
    border-bottom: 0px solid #e8eaec;
    padding: 30px 30px 0px 30px;
    line-height: 1;
  }
  /deep/ .ivu-modal-header-inner {
    font-family: "PingFang SC Bold";
    font-weight: 700;
    font-size: 14px;
    text-align: left;
    color: #b40001;
  }
  /deep/ .ivu-modal-footer {
    border-top: 0px solid #e8eaec;
    padding: 0px 30px 30px 30px;
    text-align: left;
  }
  /deep/ .ivu-modal-close {
    font-size: 15px;
    right: 30px;
    top: 30px;
  }
  /deep/ .ivu-modal-close .ivu-icon-ios-close {
    font-size: 15px;
    background-color: #f6f4f4;
    border-radius: 5px;
  }
  /deep/ .ivu-modal-body {
    padding: 14px 30px 5px 30px;
  }
  /deep/ .ivu-input {
    border: 1px solid #dcdee2;
    box-shadow: none;
  }
  /deep/ .ivu-input:hover {
    border: 1px solid #dcdee2;
    box-shadow: none;
  }
  /* 隐藏滑动条 */
  .sider-menu-div::-webkit-scrollbar {
    display: none;
  }
  /* 隐藏滑动条 */
</style>
